package com.flw.eslab.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.flw.eslab.dao.UserDao;
import com.flw.eslab.model.Group;
import com.flw.eslab.model.Role;
import com.flw.eslab.model.User;



@Repository("userDao")
public class UserDaoImpl extends CommonDaoImpl<User> implements UserDao {

	@Override
	public List<User> findByName(String name) {
		String hql = "from User  where name=:name";
		return hibernateTemplate.findByNamedParam(hql, "name", name);
	}

	@Override
	public List<User> checkAndReturnUser(String studentNO, String password) {
		String hql = "from User  where studentNO=:studentNO and password=:password";
		
		return hibernateTemplate.findByNamedParam(hql, new String[]{"studentNO","password"}, new Object[]{studentNO,password});
	}

	@Override
	public List<User> checkAndReturnUser(String studentNO) {
		String hql = "from User  where studentNO=:studentNO";
		return hibernateTemplate.findByNamedParam(hql, "studentNO", studentNO);
	}

	@Override
	public List<User> findByGroup(Group group) {
		String hql="from User where group=:group";
		return hibernateTemplate.findByNamedParam(hql, "group", group);
	}

	@Override
	public List<User> findByRole(Role role) {
		String hql="from User where role=:role";
		return hibernateTemplate.findByNamedParam(hql, "role", role);
	}

}
